package com.cch.cooperation.api.vip.controller;

import com.cch.cooperation.api.auth.dto.LoginUserDTO;
import com.cch.cooperation.api.common.sign.SignValid;
import com.cch.cooperation.api.vip.dto.VipAdViewAddRespDTO;
import com.cch.cooperation.api.vip.dto.VipAdViewRemainingDTO;
import com.cch.cooperation.api.vip.service.VipAdViewServiceImpl;
import com.cch.cooperation.common.web.response.Response;
import com.cch.cooperation.common.web.session.Session;
import com.cch.cooperation.common.web.session.SessionManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "Vip广告观看明细")
@RestController
@RequestMapping("/api/vip/ad/view")
public class VipAdViewController {

    @Resource
    private VipAdViewServiceImpl vipAdViewService;
    @Resource
    private SessionManager sessionManager;

    @ApiOperation(value = "添加广告浏览记录(达到次数将自动添加过期时间,需验签)")
    @SignValid
    @PostMapping("/add")
    public Response<VipAdViewAddRespDTO> add() {
        Session<LoginUserDTO> session = sessionManager.get();
        VipAdViewAddRespDTO data = vipAdViewService.add(session.getData().getId());
        session.getData().setVipExpireTime(data.getVipExpireTime());
        return Response.success(data);
    }

    @ApiOperation(value = "获取vip剩余观看广告次数")
    @GetMapping("/remainingCountForVip")
    public Response<VipAdViewRemainingDTO> remainingCountForVip() {
        Session<LoginUserDTO> session = sessionManager.get();
        VipAdViewRemainingDTO data = vipAdViewService.remainingCountForVip(session.getData().getId());
        return Response.success(data);
    }
}
